﻿using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text;

namespace JESAI.Redis.Datas
{
    public sealed class RedisEncodeData : IDisposable
    {
        public byte[] Bytes { get; }

        /// <summary>
        /// 
        /// </summary>
        public int Length { get; }

        private bool IsPool { get; }

        internal RedisEncodeData(byte[] bytes, int length, bool isPool)
        {
            Bytes = bytes;
            Length = length;
            IsPool = isPool;
        }

        public void Dispose()
        {
            if (IsPool)
            {
                ArrayPool<byte>.Shared.Return(Bytes);
            }

            GC.SuppressFinalize(this);
        }
    }
}
